package com.hjj.app;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Set;

public class MyApp6 {
    public static void main(String[] args) {
        String path = "F:\\IO\\web";

        HashMap hashMapWeb = new HashMap();
        HashMap hashMapSrc = new HashMap();
        HashMap hashMapTest = new HashMap();
        HashMap hashMapMain = new HashMap();
        HashMap hashMapResources = new HashMap();
        HashMap hashMapJava = new HashMap();
        HashMap hashMapCom = new HashMap();
        HashMap hashMapHjj = new HashMap();
        HashMap hashMapBeans = new HashMap();
        HashMap hashMapMapper = new HashMap();
        HashMap hashMapServices = new HashMap();
        HashMap hashMapController = new HashMap();

        hashMapTest.put("test", "test");
        hashMapBeans.put("beans", "beans");
        hashMapMapper.put("mapper", "mapper");
        hashMapServices.put("services", "services");
        hashMapController.put("controller", "controller");


        hashMapHjj.put("beans", hashMapBeans);
        hashMapHjj.put("mapper", hashMapMapper);
        hashMapHjj.put("services", hashMapServices);
        hashMapHjj.put("controller", hashMapController);

        hashMapCom.put("hjj", hashMapHjj);

        hashMapJava.put("com", hashMapCom);

        hashMapResources.put("mapper", hashMapMapper);

        hashMapMain.put("java", hashMapJava);
        hashMapMain.put("resources", hashMapResources);

        hashMapSrc.put("test", hashMapTest);
        hashMapSrc.put("main", hashMapMain);

        hashMapWeb.put("src", hashMapSrc);

        all(hashMapWeb);

//        File file = new File(path);
    }

    private static LinkedList<String> linkedList = new LinkedList<>();

    public static void all(HashMap hashMap){
        // 获取HashMap的键集合
        Set set = hashMap.keySet();

        // 使用StringBuffer组装path路径
        StringBuffer stringBuffer = new StringBuffer("F:\\IO\\web");
        for (Object o : set) {
            // 判断HashMap的值是不是HashMap
            if (hashMap.get(o) instanceof HashMap){
                // 将键添加到LinkedList集合
                linkedList.add(String.valueOf(o));
                all((HashMap) hashMap.get(o));
                // 如果递归退出则从LinkedList集合的后面弹出元素
                linkedList.pollLast();
            }else {
                System.out.println(hashMap.get(o));
                // 组装叶子结点所在的路径
                for (String s : linkedList) {
                    stringBuffer.append(File.separator).append(s);
                }

                // 打印叶子结点所在的路径
                System.out.println(stringBuffer.toString());
                // 根据叶子结点所在的路径创建目录
                /*File file = new File(stringBuffer.toString());

                if (!file.exists()){
                    file.mkdirs();
                }*/
            }
        }
    }
}
